#!/usr/bin/python
################################################################ 
#       .___             __          _______       .___        # 
#     __| _/____ _______|  | __ ____ \   _  \    __| _/____    # 
#    / __ |\__  \\_  __ \  |/ // ___\/  /_\  \  / __ |/ __ \   # 
#   / /_/ | / __ \|  | \/    <\  \___\  \_/   \/ /_/ \  ___/   # 
#   \____ |(______/__|  |__|_ \\_____>\_____  /\_____|\____\   # 
#        \/                  \/             \/                 # 
#                   ___________   ______  _  __                # 
#                 _/ ___\_  __ \_/ __ \ \/ \/ /                # 
#                 \  \___|  | \/\  ___/\     /                 # 
#                  \___  >__|    \___  >\/\_/                  # 
#      est.2007        \/            \/   forum.darkc0de.com   #
#                                         www.beenuarora.com   #
################################################################
#Thanks to low1z for initial script
#Greetz to all darkc0de memeber

import os, smtplib, mimetypes, time, sys, urllib, urllib2, socket

from email.MIMEMultipart import MIMEMultipart 
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase
from email import Encoders
 
 
def sendMail(gmailUser, gmailPassword, recipient, subject, text, attachment): 
    """ send mail using gmail user and password
    """
    
    port = 587
    relay = 'smtp.gmail.com'
    
    msg = MIMEMultipart() 
    msg['From'] = gmailUser 
    msg['To'] = recipient 
    msg['Subject'] = subject 
    msg.attach(MIMEText(text))
    
    if attachment:
        part = MIMEBase('application', "octet-stream")
        part.set_payload( open(attachment,"rb").read() )
        Encoders.encode_base64(part)
        part.add_header('Content-Disposition', 'attachment; filename="%s"' 
                                            % os.path.basename(attachment))
        msg.attach(part)
    
    mailServer = smtplib.SMTP(relay, port)

    # try to use TLS
    try:    
        mailServer.starttls()
    except(smtplib.SMTPHeloError):
        print "The server didnt reply properly to the HELO greeting.\n"
    except(smtplib.SMTPException):
        print "The server does not support the STARTTLS extension.\n"
    except(RuntimeError):
        print "SSL/TLS support is not available to your python interpreter.\n"

    # try to log in
    try:
        mailServer.login(gmailUser, gmailPassword)
    except(smtplib.SMTPAuthenticationError):
        print "Bad user / passwd\n"
    
    # try to send the email
    try:    
        mailServer.sendmail(gmailUser, recipient, msg.as_string())
    except(smtplib.SMTPRecipientsRefused):
        print "All recipients were refused. Nobody got the mail.            \
        The recipients attribute of the exception object is a dictionary    \
        with information about the refused recipients (like the one         \
        returned when at least one recipient was accepted).\n"
    except(smtplib.SMTPHeloError):
        print "The server didnt reply properly to the HELO greeting.\n"
    except(smtplib.SMTPSenderRefused):
        print ("The server didnt accept the from_addr: %s\n." % gmailUser)
    except(smtplib.SMTPDataError):
        print "The server replied with an unexpected error code (other than a refusal of a recipient."

    mailServer.close() 
    print('[-] Sent email to %s [-] ' % recipient)
    if attachment:
        print ('\t--attached file: %s\n' % attachment)

if sys.platform == 'linux-i386' or sys.platform == 'linux2' or sys.platform == 'darwin':
	SysCls = 'clear'
elif sys.platform == 'win32' or sys.platform == 'dos' or sys.platform[0:5] == 'ms-dos':
	SysCls = 'cls'
else:
	SysCls = 'unknown'

os.system(SysCls)

print "\n|---------------------------------------------------------------|"
print "| beenudel1986[@]gmail[dot]com                                  |"
print "| Spomb v1.0                                                    |"
print "|   Do Visit     www.BeenuArora.com      &        darkc0de.com  |"
print "|---------------------------------------------------------------|\n"
 
if len(sys.argv) < 3: 
	print "\nUsage: ./spammer.py list.txt <attachment file>" 
	print "Ex: ./spomb.py list.txt <attachment file>\n" 
	sys.exit(1)

email_list = sys.argv[1] 
try:
	addresses = open(email_list, 'r')
except (IOError):
	print " \n\nSpamming List Missing ..Exiting :("
	sys.exit(0)

attachment = sys.argv[2]


count = raw_input('Enter the Number of mails : ')
gmailUser = raw_input('Enter Your Email ID : ')

if sys.platform == 'linux-i386' or sys.platform == 'linux2' or sys.platform == 'darwin':
	os.system('stty -echo')
	
gmailPassword = raw_input('Enter Your Gmail Password : ') 
email_list= sys.argv[1]
if sys.platform == 'linux-i386' or sys.platform == 'linux2' or sys.platform == 'darwin': 
	os.system('stty echo')
subject = raw_input('\nSubject : ') 
text = raw_input('Text : ')

for i in range (int(count)):
	for address in addresses:
 		recipient = address[:-1]
		try: 
		        sendMail(gmailUser, gmailPassword, recipient, subject, text, attachment) 
		        time.sleep(10)
		except(urllib2.URLError, socket.timeout, socket.gaierror, socket.error): 
				print ('Something Went Wrong ..Check Manually for Error\n') 
		except(KeyboardInterrupt): 
				pass 

print ('\n\nDone Mailing...')
